#!/bin/bash
#/**
# * @author Aleske A. Evdokimov <ale@izhcat.ru>
# * @version $Id$
# */

php downloader.php ./regions_000_sat.lst ./testdata 0 --prefix=sat_000_
php downloader.php ./regions_001_pkg.lst ./testdata 0 --prefix=pkg_001_

ls ./testdata/sat_000_*.html | while read F; do
  php repearser.php $F lst_000_sat.def --no-head > `echo $F | cut -d. -f-2`.csv
done

ls ./testdata/pkg_001_*.html | while read F; do
  php repearser.php $F lst_001_pkg.def --no-head > `echo $F | cut -d. -f-2`.csv
  php repearser.php $F pak_001_pkg.def --no-head > `echo $F | cut -d. -f-2`.c_v
done

rm -f ./testdata/*.html

ls ./testdata/sat_000_*.csv | while read F; do
  php downloader.php %%F testdata 3 --prefix=sat_
done

ls ./testdata/pkg_001_*.csv | while read F; do
  php downloader.php %%F testdata 4 --prefix=pkg_
done

rm -f ./testdata/*.csv

ls ./testdata/sat_*.html | while read F; do
  ls sat_*.def | while read I; do
    php repearser.php $F $I --no-head >> ./testdata/`echo $I | cut -d. -f1`.csv
  done
done

ls ./testdata/pkg_*.html | while read F; do
  ls pkg_*.def | while read I; do
    php repearser.php $F $I --no-head >> ./testdata/`echo $I | cut -d. -f1`.csv
  done
done

ls ./testdata/pkg_*.c_v | while read F; do
  cat $F >> ./testdata/pkg_001_pkg.csv
done

rm -f ./testdata/*.c_v
rm -f ./testdata/*.html
